package com.example.bitmap;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Scanner;

public class stringOperation {
	static ArrayList<Integer> queue = new ArrayList<Integer>();
	static String[] list = new String[4];

	static int rear=0;

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line=null;
		while((line=br.readLine())!=null) {
			if (line.contains(" ")) {
				String[] split = line.split(" ");
				int s0 = Integer.parseInt(split[0]);
				int s1 = Integer.parseInt(split[1]);
				String ss0 = list[s0 - 1];
				String ss1 = list[s1 - 1];
				list[s0 - 1] = ss0 + ss1;
				list[s1 - 1] = "";
			}else {
				list[rear++] = line;
			}
			for (int i = 0; i < list.length; i++) {
				System.out.print(list[i]!=null?list[i]:"");
			}
			System.out.println();
		}
	}
}
